package cn.iocoder.yudao.module.shop.framework.core.databind;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.util.Arrays;

public class WeekStringDeSerializer extends JsonDeserializer<String> {

    /**
     * 反序列化
     */
    @Override
    public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        String resultS = "";
        final String[] originNum = {"1","2","3","4","5","6","7"};
        final String[] formatNum = {"一","二","三","四","五","六","日"};

        if (StringUtils.isNotBlank(jsonParser.getText())) {
            Arrays.sort(originNum);

            int index = Arrays.binarySearch(formatNum,jsonParser.getText());
            if (index>=0){
                 resultS =  originNum[index];
            }else{
                 resultS =  "0";
            }
        }else{
             resultS =  "0";
        }
        return resultS;
    }
}
